VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmDeptsEdit 
   BackColor       =   &H00FFFFFF&
   Caption         =   "Add/Edit/Delete Departments"
   ClientHeight    =   4380
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5535
   Icon            =   "frmDeptsEdit.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   4380
   ScaleWidth      =   5535
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdDelete 
      Appearance      =   0  'Flat
      BackColor       =   &H00E0E0E0&
      Caption         =   "&Delete All"
      Height          =   315
      Left            =   1320
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   3900
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin VB.CommandButton cmdClose 
      Appearance      =   0  'Flat
      BackColor       =   &H00E0E0E0&
      Caption         =   "OK"
      Height          =   315
      Left            =   3120
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   3900
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Modify Department Information"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000080FF&
      Height          =   3495
      Left            =   240
      TabIndex        =   2
      Top             =   240
      Width           =   5055
      Begin MSDataGridLib.DataGrid grdDepts 
         Height          =   2955
         Left            =   1020
         TabIndex        =   3
         TabStop         =   0   'False
         ToolTipText     =   "To Delete a Box, highlight a row and press the Delete key."
         Top             =   300
         Width           =   3135
         _ExtentX        =   5530
         _ExtentY        =   5212
         _Version        =   393216
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         WrapCellPointer =   -1  'True
         AllowAddNew     =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "Defined Departments"
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmDeptsEdit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim m_rsDepts As New ADODB.Recordset     'Module level recordset tied to grdDepts
'---------------------------------------------------------------------------------------
' Procedure : cmdClose_Click()
' DateTime  : 7/7/2004
' Purpose   : Loads Depts combo then hides form
'---------------------------------------------------------------------------------------
'
Private Sub cmdClose_Click()
    On Error GoTo EH
    
    With frmShip
        Call LoadDeptCombo(.f38, .f38)
        Me.Hide
        .SetFocus
    End With
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:cmdClose_Click"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : cmdDelete_Click()
' DateTime  : 2/10/2005
' Purpose   : Verifes user wished to delete all defined Departments, if yes calls sub to
'             delete all records in Departments table and updates the grdDepts.
'---------------------------------------------------------------------------------------
'
Private Sub cmdDelete_Click()
    Dim intRet As Integer

    On Error GoTo EH
    
    intRet = MsgBox("Are you sure you wish to delete all defined Departments?", vbYesNo, "Confirm Delete All")
    If intRet = vbYes Then
        Call DeleteAllDepts
        Call UpdateDeptsGrid
    End If

    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:cmdDelete_Click"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : Form_Activate()
' DateTime  : 2/10/2005
' Purpose   : Loads Departments into datagrid.
'---------------------------------------------------------------------------------------
'
Private Sub Form_Activate()
    On Error GoTo EH
        
    Call UpdateDeptsGrid
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:Form_Activate"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : Form_Deactivate()
' DateTime  : 7/7/2004
' Purpose   : Closes module level recordset and sets it to nothing.
'---------------------------------------------------------------------------------------
'
Private Sub Form_Deactivate()
    On Error GoTo EH
        
    If m_rsDepts.State = adStateOpen Then m_rsDepts.Close
    Set m_rsDepts = Nothing
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:Form_Deactivate"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : Form_KeyDown()
' DateTime  : 2/17/2005
' Purpose   : Enter key pressed sends a TAB to move to next field
'---------------------------------------------------------------------------------------
'
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Not TypeOf Me.ActiveControl Is CommandButton Then
        If Shift = 0 And KeyCode = 13 Then
            SendKeys "{TAB}"
        End If
    End If
End Sub
'---------------------------------------------------------------------------------------
' Procedure : UpdateDeptsGrid()
' DateTime  : 2/10/2005
' Purpose   : Update the DIMs grid and set column headings
' Call from : Form_Activate, cmdDelete_Click
'---------------------------------------------------------------------------------------
'
Public Sub UpdateDeptsGrid()
    Dim strQuery As String
    
    On Error GoTo EH
    
    'Select everything from DIMs table
    strQuery = "SELECT * FROM Departments"
    'If already open, close recordset
    If m_rsDepts.State = adStateOpen Then m_rsDepts.Close
    'Execute query
    m_rsDepts.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic

    Set grdDepts.DataSource = m_rsDepts
    With grdDepts
        .ClearFields
        .ReBind
        .Columns(0).Caption = "Department"
    End With
    
Release:
    Set m_rsDepts = Nothing
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:UpdateDeptsGrid"
    Resume Release
     
End Sub

'---------------------------------------------------------------------------------------
' Procedure : DeleteAllDepts()
' DateTime  : 2/10/2005
' Purpose   : Deletes all defined Departmentd
'---------------------------------------------------------------------------------------
'
Public Sub DeleteAllDepts()
    
    Dim strQuery As String
    
    On Error GoTo EH
    
    'Build and execute the delete query
    strQuery = "DELETE FROM Departments"
    g_connFSMSClient.Execute strQuery
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:DeleteAllDepts"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : grdDepts_AfterColUpdate()
' DateTime  : 2/10/2005
' Purpose   : This commits the changes immediately after a column has been updated.
'             This keeps users from getting "Operation not allowed in this context" error.
'---------------------------------------------------------------------------------------
'
Private Sub grdDepts_AfterColUpdate(ByVal ColIndex As Integer)
    
    On Error GoTo EH
    
    If grdDepts.Bookmark >= 0 Then
        grdDepts.Bookmark = grdDepts.Bookmark
    End If
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmDeptsEdit:grdDepts_AfterColUpdate"

End Sub
